<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增' : '帮砍详情'" width="1000px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">



  


      <el-form-item label="活动信息">
          <el-descriptions title="" size=5 direction="vertical" :column="3" border>
            <el-descriptions-item   label="活动标题">{{form.yxStoreBargain.title}}</el-descriptions-item>
            <el-descriptions-item   label="活动时间">{{formatTimeTwo(form.yxStoreBargain.startTime)}}~{{formatTimeTwo(form.yxStoreBargain.stopTime)}}</el-descriptions-item>
            <el-descriptions-item   label="活动状态" :span="2">
                <el-tag size="small" v-if="form.yxStoreBargain.status==0">已结束</el-tag>
                <el-tag size="small" v-if="form.yxStoreBargain.status==1">进行中</el-tag>
            </el-descriptions-item>
          </el-descriptions>
      </el-form-item>
      <el-form-item label="砍价信息">
        <el-descriptions title="" size=5 direction="vertical" :column="3" border>
            <el-descriptions-item label="已经砍掉">{{form.price}}</el-descriptions-item>
            <el-descriptions-item label="帮砍人数">{{form.cutCount}}</el-descriptions-item>
            <el-descriptions-item label="砍价状态" :span="2">
                <el-tag size="small" v-if="form.yxStoreBargain.status==0">已结束</el-tag>
                <el-tag size="small" v-if="form.yxStoreBargain.status==1">进行中</el-tag>
            </el-descriptions-item>
          </el-descriptions>
      </el-form-item>
      <el-form-item label="帮砍列表">
        
              <el-table
                :data="form.helpList"
                style="width: 100%"
                :row-class-name="tableRowClassName">
                <el-table-column
                  label="头像"
                  width="180">
                  <template slot-scope="scope">
                    <a :href="scope.row.user.avatar" style="color: #42b983" target="_blank"><img :src="scope.row.user.avatar" alt="点击打开" class="el-avatar"></a><br>
                  </template>
                </el-table-column>
                <el-table-column
                  label="昵称"
                  width="180">
                  <template slot-scope="scope">
                  {{scope.row.user.nickname}}
                  
                  </template>
                </el-table-column>
                <el-table-column
                  prop="address"
                  label="帮砍金额">
                  <template slot-scope="scope">
                    {{scope.row.price}}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="address"
                  label="帮砍时间">
                  <template slot-scope="scope">
                  {{scope.row.createTime}}
                  </template>
                </el-table-column>
              </el-table>
     
      </el-form-item>
    </el-form>


    
    <!--<div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
    -->
    
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/yxStoreBargainUser'
import { formatTimeTwo, parseTime } from '@/utils/index'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        uid: '',
        bargainId: '',
        bargainPriceMin: '',
        bargainPrice: '',
        price: '',
        status: '',
        cutCount:'',
        addTime: '',
        isDel: '',
        yxStoreBargain:{},
        user:{},
        product:{
        },
        helpList:[]
      },
      rules: {
      }
    }
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      },
    formatTimeTwo,
    cancel() {
      this.resetForm()
      this.loading = true
    },
    doSubmit() {
      this.loading = true
      if (this.isAdd) {
        this.doAdd()
      } else this.doEdit()
    },
    doAdd() {
      add(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        uid: '',
        bargainId: '',
        bargainPriceMin: '',
        bargainPrice: '',
        price: '',
        cutCount:'',
        status: '',
        addTime: '',
        isDel: '',
        yxStoreBargain:{},
        user:{},
        product:{},
        helpList:[]
      }
    }
  }
}
</script>

<style scoped>

</style>
